package com.da.lon.wang.xlg.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.activity.LoginActivity;
import com.da.lon.wang.xlg.activity.ProductsActivity;
import com.da.lon.wang.xlg.activity.ResultSearchActivity;
import com.da.lon.wang.xlg.bean.HomeResultBean.HomeItemContentBean;
import com.da.lon.wang.xlg.bean.HomeResultBean.HomeItemData;
import com.da.lon.wang.xlg.bean.ZanBean;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.constants.XLGConstants;
import com.da.lon.wang.xlg.http.HttpLoader;
import com.da.lon.wang.xlg.http.HttpLoader.OnWebLoadListener;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.TimeCount;
import com.da.lon.wang.xlg.util.Utils;
import com.da.lon.wang.xlg.util.XLGDataUtils;
import com.da.lon.wang.xlg.view.HorizontalListView;
import com.da.lon.wang.xlg.view.ScrollGridView;
import com.da.lon.wang.xlg.view.TimeDownView;

import net.tsz.afinal.http.AjaxParams;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

public class HomeProductAdapter extends BaseAdapter {
    // 存储所有显示数据的集合
    ArrayList<HomeItemData> datas;
    ArrayList<HomeItemContentBean> productList;
    Context context;
    LayoutInflater inflater;
    // 搜索的分类id
    ArrayList<String> cidList;
    // 第二行viewPager的适配器
    AdPageAdapter pagerAdapter;
    // 第二行中点的数量
    int dot_count = 0;
    // 第二行Viewpager当前不放的位置的下标
    int current;
    // 第二行的布局文件对象
    RelativeLayout rel_layout;
    boolean pagerFlg = true;
    // 存储第五行图片点击跳转路径的集合
    ArrayList<String> smaleImageUrls;
    private String uri1;
    // 存储商品详情地址的集合
    private List<String> productLinks;
    private int position_index;
    private String partSixUrl;
    private ArrayList<ImageView> pImageView;
    private Handler vpHandler;
    private HomeHolder holder;
    private HomeHolder viewHolder;
    // 判断是否刷新倒计时 1为要刷新 0为不刷新
    private int refresh_timer = 1;
    private HomeHolder skill_holder;

    private TimeCount time;

    public HomeProductAdapter(ArrayList<HomeItemData> datas, Context context,
                              Handler vpHandler) {
        this.datas = datas;
        this.context = context;
        inflater = LayoutInflater.from(context);
        smaleImageUrls = new ArrayList<String>();
        productLinks = new ArrayList<String>();
        pImageView = new ArrayList<ImageView>();
        productList = new ArrayList<HomeItemContentBean>();
        this.vpHandler = vpHandler;
    }

    public HomeHolder getViewHolder() {
        return viewHolder;
    }

    public void setViewHolder(HomeHolder viewHolder) {
        this.viewHolder = viewHolder;
    }

    public HomeHolder getSkill_holder() {
        return skill_holder;
    }

    public void setSkill_holder(HomeHolder skill_holder) {
        this.skill_holder = skill_holder;
    }

    @Override
    public int getCount() {
        return datas != null ? datas.size() : 0;
    }

    // 刷新列表
    public void refreshList(ArrayList<HomeItemData> datas) {
        refresh_timer = 1;
        this.datas = datas;
        addSingleProduct();
        MyApplication.getInstance().setProductList(productList);
        notifyDataSetChanged();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {

        int INDEX = 0;
        INDEX = MyApplication.getHome_item_type().indexOf(
                datas.get(position).getType());
        return INDEX;

    }

    @Override
    public int getViewTypeCount() {
        return MyApplication.getHome_item_type().size();
    }

    /**
     * 获取除开商品有多少个 item
     *
     * @return
     */
    public int getOrtherSingleProductCount() {
        int ortherProductCount = 0;
        for (int i = 0; datas != null && i < datas.size(); i++) {
            if (!"homePageSingleProduct".equals(datas.get(i).getType())) {
                ortherProductCount++;
            }
        }
        return ortherProductCount;
    }

    /**
     * 添加商品集合
     */
    public void addSingleProduct() {
        productList.clear();
        for (int i = 0; null != datas && i < datas.size(); i++) {
            if ("homePageSingleProduct".equals(datas.get(i).getType())) {
                productList.addAll(datas.get(i).getContent());
            }
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int itemViewType = getItemViewType(position);
        switch (itemViewType) {
            case 0:
                convertView = getPartOne(position, convertView);
                break;
            case 1:
                convertView = getPartTwo(position, convertView);
                break;
            case 2:
                convertView = getPartThree(position, convertView);
                break;
            case 3:
                // 空格线
                convertView = getEmpteLine(position, convertView);
                break;
            case 5:
                convertView = getPartFour(position, convertView);
                break;
            case 6:
                convertView = getPartFive(position, convertView);
                break;
            case 7:
                convertView = getPartSixView(position, convertView);
                break;
            default:
                // 第八行即以上
                convertView = getproductsView(position, convertView);
                break;
        }
        return convertView;
    }

    /**
     * 第一行
     *
     * @return
     */
    private View getPartOne(int position, View convertView) {
        try {
            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.home_title_score_item,
                        null);
                holder.ocoffee_home_hlv = (HorizontalListView) convertView
                        .findViewById(R.id.ocoffee_home_hlv);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }
            final ArrayList<HomeItemContentBean> one_content = datas.get(
                    position).getContent();

            HomeCatgroItemAdapter newHeadLvAdapter = new HomeCatgroItemAdapter(
                    context, one_content);
            holder.ocoffee_home_hlv.setAdapter(newHeadLvAdapter);
            holder.ocoffee_home_hlv
                    .setOnItemClickListener(new OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                                int arg2, long arg3) {
                            if (!MyApplication.isNetworkAvailable(context)) {
                                return;
                            }
                            PreferenceUtils.getInstance().SetSettingString(
                                    PreferencesConfig.SEARCH_SATTR, "");
                            Intent intent = new Intent(context,
                                    ResultSearchActivity.class);
                            intent.putExtra("cid", one_content.get(arg2)
                                    .getCid());
                            context.startActivity(intent);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    /**
     * 第二行
     *
     * @return
     */
    @SuppressWarnings("deprecation")
    private View getPartTwo(int position, View convertView) {
        ArrayList<HomeItemContentBean> two_content = null;
        try {
            if (convertView == null) {
                viewHolder = new HomeHolder();
                convertView = (View) inflater.inflate(R.layout.home_view_pager,
                        null);
                viewHolder.viewPager = (ViewPager) convertView
                        .findViewById(R.id.home_viewpager);
                viewHolder.dotLl = (LinearLayout) convertView
                        .findViewById(R.id.dot_ll);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (HomeHolder) convertView.getTag();
            }
            if (null != datas.get(1) && null != datas.get(1).getContent()) {
                two_content = datas.get(position).getContent();
                dot_count = two_content.size();
            }

            if (pImageView.size() == 0) {
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                params.rightMargin = 3;
                for (int i = 0; i < dot_count; i++) {
                    if (context != null) {
                        ImageView image = new ImageView(context);
                        image.setLayoutParams(params);
                        pImageView.add(image);
                    }
                }
            }
            pagerAdapter = new AdPageAdapter(context, two_content);
            viewHolder.viewPager.setAdapter(pagerAdapter);
            vpHandler.sendEmptyMessageDelayed(0, 5000);
            viewHolder.viewPager
                    .setOnPageChangeListener(new OnPageChangeListener() {

                        @Override
                        public void onPageSelected(int arg0) {

                            current = viewHolder.viewPager.getCurrentItem();
                            generatePageControl(current);

                        }

                        @Override
                        public void onPageScrolled(int arg0, float arg1,
                                                   int arg2) {
                        }

                        @Override
                        public void onPageScrollStateChanged(int arg0) {

                        }
                    });

        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    /**
     * 动态加载点
     *
     * @param index
     */
    private void generatePageControl(int index) {
        try {
            index %= dot_count;
            if (index < 0) {
                index = dot_count + index;
            }
            viewHolder.dotLl.removeAllViews();

            if (dot_count < 2) {
                holder.dotLl.setVisibility(View.GONE);
            }
            for (int i = 0; i < dot_count; i++) {
                if (context != null) {
                    if (i == index) {
                        pImageView.get(i).setImageResource(
                                R.drawable.point_selected);
                    } else {
                        pImageView.get(i).setImageResource(
                                R.drawable.point_normal);
                    }
                    ViewParent vp = pImageView.get(i).getParent();
                    if (vp != null) {
                        ViewGroup parent = (ViewGroup) vp;
                        parent.removeView(pImageView.get(i));
                    }
                    viewHolder.dotLl.addView(pImageView.get(i));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 第三行
     *
     * @return @throws
     */
    private View getPartThree(int position, View convertView) {

        try {
            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.home_gread_view, null);
                holder.gridview = (ScrollGridView) convertView
                        .findViewById(R.id.gridview);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }

            final ArrayList<HomeItemContentBean> three_content = datas.get(
                    position).getContent();
            holder.gridview.setNumColumns(three_content.size());
            if (context != null) {
                holder.gridview.setAdapter(new CategreyAdapter(context,
                        three_content));
            }
            holder.gridview.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Utils.onClickBannerStartActivity(context, 1, three_content
                            .get(position).getLink());
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    /**
     * 第四行
     *
     * @return
     */
    private View getEmpteLine(int position, View convertView) {
        try {
            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(
                        R.layout.ocoffee_home_empte_line, null);
                holder.empte_line_viconvert = (View) convertView
                        .findViewById(R.id.empte_line_vi);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }


    /**
     * 第五行
     *
     * @return
     */
    private View getPartFour(int position, View convertView) {
        try {
            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.ocoffee_home_model2,
                        null);
                holder.model21Tv1 = (TextView) convertView
                        .findViewById(R.id.homemodel2_tv1);
                holder.model21Tv2 = (TextView) convertView
                        .findViewById(R.id.homemodel2_tv2);
                holder.model21Iv1 = (ImageView) convertView
                        .findViewById(R.id.homemodel2_iv1);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }
            ArrayList<HomeItemContentBean> five_content = datas.get(position)
                    .getContent();
            Utils.loadImageByGlide(context, five_content.get(0).getImg_url(),
                    null, holder.model21Iv1, 0, 0, 0);
            holder.model21Tv1.setText(five_content.get(0).getTitle());
            holder.model21Tv2.setText(five_content.get(0).getContent());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    /**
     * 第六行
     *
     * @return
     */
    private View getPartFive(int position, View convertView) {
        try {
            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.ocoffee_home_model3,
                        null);
                holder.model3Iv1 = (ImageView) convertView
                        .findViewById(R.id.homemodel3_iv1);
                holder.model3Iv2 = (ImageView) convertView
                        .findViewById(R.id.homemodel3_iv2);
                holder.model3Iv3 = (ImageView) convertView
                        .findViewById(R.id.homemodel3_iv3);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }
            if (datas != null && datas.get(5) != null) {
                ArrayList<HomeItemContentBean> six_content = datas
                        .get(position).getContent();
                Utils.loadImageByGlide(context,
                        six_content.get(0).getImg_url(), null,
                        holder.model3Iv1, 0, 0, 1);
                Utils.loadImageByGlide(context,
                        six_content.get(1).getImg_url(), null,
                        holder.model3Iv2, 0, 0, 1);
                Utils.loadImageByGlide(context,
                        six_content.get(2).getImg_url(), null,
                        holder.model3Iv3, 0, 0, 1);
                holder.model3Iv1.setTag(holder.model3Iv1.getId(), six_content
                        .get(0).getStatus());
                holder.model3Iv2.setTag(holder.model3Iv2.getId(), six_content
                        .get(1).getStatus());
                holder.model3Iv3.setTag(holder.model3Iv3.getId(), six_content
                        .get(2).getStatus());
                smaleImageUrls.add(six_content.get(0).getLink());
                smaleImageUrls.add(six_content.get(1).getLink());
                smaleImageUrls.add(six_content.get(2).getLink());
                holder.model3Iv1.setOnClickListener(new HomeClickListener());
                holder.model3Iv2.setOnClickListener(new HomeClickListener());
                holder.model3Iv3.setOnClickListener(new HomeClickListener());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 小广告图片设置点击监听

        return convertView;
    }

    /**
     * 小广告图片点击事件处理
     */
    private void onClickBanner(int index, int status) {
        String url = smaleImageUrls.get(index);
        Utils.onClickBannerStartActivity(context, status, url);

    }

    /**
     * 获取第六行的图片
     *
     * @param index 第几张图片
     * @return
     * @throws JSONException
     */
    private View getPartSixView(final int index, View convertView) {
        try {

            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.ocoffee_home_model4,
                        null);
                holder.horizontal_home_iv = (ImageView) convertView
                        .findViewById(R.id.horizontal_home_iv);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }

            final ArrayList<HomeItemContentBean> six_content = datas.get(index)
                    .getContent();

            Utils.loadImageByGlide(context, six_content.get(0).getImg_url(),
                    null, holder.horizontal_home_iv, 0, 0, 2);
            // 第一张广告图点击事件处理
            holder.horizontal_home_iv.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    partSixUrl = six_content.get(0).getLink();
                    String status = six_content.get(0).getStatus();
                    Utils.onClickBannerStartActivity(context,
                            Integer.parseInt(status), partSixUrl);
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    /**
     * 商品列表
     *
     * @param position
     * @return
     */
    private View getproductsView(int position, View convertView) {
        try {

            if (convertView == null) {
                holder = new HomeHolder();
                convertView = inflater.inflate(R.layout.ocoffee_home_model_1,
                        null);
                holder.modelTv1 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv1);
                holder.xiadan_rl = (RelativeLayout) convertView.findViewById(R.id.xiadan_rl);
                holder.modelTv2 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv2);
                holder.modelTv3 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv3);
                holder.modelTv4 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv4);
                holder.modelTv5 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv5);
                holder.modelTv6 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv6);
                holder.modelTv7 = (TextView) convertView
                        .findViewById(R.id.homemodel_tv7);
                holder.modelLl = (LinearLayout) convertView
                        .findViewById(R.id.homemodel_ll);
                holder.modelIv1 = (ImageView) convertView
                        .findViewById(R.id.homemodel_iv1);
                holder.modelIv2 = (ImageView) convertView
                        .findViewById(R.id.homemodel_iv2);
                holder.modelCb = (TextView) convertView
                        .findViewById(R.id.homemodel_cb);
                convertView.setTag(holder);
            } else {
                holder = (HomeHolder) convertView.getTag();
            }
            int ortherProductCount = getOrtherSingleProductCount();
            if (position < MyApplication.getInstance().getProductList().size()
                    + ortherProductCount) {
                final HomeItemContentBean bean = MyApplication.getInstance()
                        .getProductList().get(position - ortherProductCount);
                holder.modelTv1.setText(bean.getName());
                holder.modelTv2.setText(bean.getRegion_name());
                holder.modelTv3.setText(bean.getF_name());
                holder.modelTv4.setText("￥" + bean.getSeal_price());
                holder.modelTv5.setText("￥" + bean.getPrice());
                holder.modelTv5.getPaint()
                        .setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                //最新修改
//                holder.modelTv6.setText(bean.getZk() + "折");
                if (bean.getZkl() > 0) {
                    holder.modelTv6.setText(bean.getZkl() + "折");
                } else {
                    holder.xiadan_rl.setVisibility(View.GONE);
                }

                Utils.loadImageByGlide(context, bean.getBigimage(), null,
                        holder.modelIv1, 0, 0, 0);
                if ("".equals(bean.getFlag_img())) {
                    holder.modelIv2.setVisibility(View.GONE);
                } else {
                    Utils.loadImageByGlide(context, bean.getFlag_img(), null,
                            holder.modelIv2, 0, 0, 0);
                }

                if (bean.getLike() != null && "1".equals(bean.getLike())) {
                    Drawable drawable = context.getResources().getDrawable(
                            R.drawable.home_check_true);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(),
                            drawable.getMinimumHeight());
                    holder.modelCb.setCompoundDrawables(drawable, null, null,
                            null);
                } else {
                    Drawable drawable = context.getResources().getDrawable(
                            R.drawable.home_check_false);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(),
                            drawable.getMinimumHeight());
                    holder.modelCb.setCompoundDrawables(drawable, null, null,
                            null);
                }
                uri1 = bean.getUrl();
                if (productLinks != null && !productLinks.contains(uri1)) {
                    productLinks.add(uri1);
                }
                holder.modelLl.setTag(holder.modelLl.getId(), position
                        - ortherProductCount);
                holder.modelCb.setTag(holder.modelCb.getId(), position
                        - ortherProductCount);
                // 设置点赞监听
                holder.modelCb.setOnClickListener(new HomeClickListener());
                // 设置子项点击监听
                holder.modelLl.setOnClickListener(new HomeClickListener());
                // 设置分享监听
                holder.modelTv7.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (MyApplication.isNetworkAvailable(context))
                            Utils.showShare(context, bean.getName(),
                                    bean.getShare_info(), bean.getUrl(),
                                    bean.getShare_img());
                    }
                });
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    /**
     * 点赞标签的点击事件处理
     *
     * @param modelCb 点赞标签
     */
    public void cbOnClick(final View v) {
        try {
            if (!MyApplication.isNetworkAvailable(context)) {
                return;
            }
            position_index = (int) v.getTag(v.getId());
            String user_key = MyApplication.getUserKey();
            String user_id = MyApplication.getUserId();
            if (TextUtils.isEmpty(user_key)) {
                Intent intent = new Intent(context, LoginActivity.class);
                intent.putExtra("isGotoHome", false);
                ((Activity) context).startActivityForResult(intent, 300);
            } else {
                HttpLoader<ZanBean> loader = new HttpLoader<ZanBean>(context,
                        XLGConstants.URL + "index-singproduct", ZanBean.class,
                        60 * 1000);
                AjaxParams params = new AjaxParams();
                String p_id = "";
                if (productList != null && productList.size() > position_index) {
                    p_id = productList.get(position_index).getId();
                }
                params.put("token", XLGDataUtils.encrypt2MD5("index"
                        + "2015#$%" + "singproduct"));
                params.put("id", user_id);
                params.put("user_key", user_key);
                params.put("pid", p_id);
                params.put("type", "2");

                loader.setManagerListener(new MyWebLoadListener(v));
                loader.loadData(params);
            }
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    /**
     * 子项内容的点击事件处理
     *
     * @param v 内容对象
     */
    private void llOnClick(View v) {
        if (!MyApplication.isNetworkAvailable(context)) {
            return;
        }
        int tag = (int) v.getTag(v.getId());
        String url = productLinks.get(tag);
        if (url.indexOf("/p/") != -1) {
            Intent intent = new Intent(context, ProductsActivity.class);
            String product_number = url.substring(url.indexOf("/p/") + 3,
                    url.indexOf(".html"));
            PreferenceUtils.getInstance().SetSettingString(
                    PreferencesConfig.PRODUCT_NUMBER, product_number);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivity(intent);
        }

    }

    public static class HomeHolder {

        public TextView jujiesu_tv;
        public TextView timedown_second;
        public TextView timedown_min;
        public TextView timedown_hour;
        public TimeDownView timedownview;
        public ImageView horizontal_home_iv;
        public View empte_line_viconvert;
        public TextView modelTv4;
        public TextView modelTv5;
        public TextView modelTv6;
        public TextView modelTv7;
        public LinearLayout modelLl;
        public ImageView modelIv1;
        public ImageView modelIv2;
        public TextView modelCb;
        public TextView modelTv3;
        public TextView modelTv2;
        public TextView modelTv1;
        public RelativeLayout xiadan_rl;
        public ImageView model41Iv;
        public ImageView model3Iv3;
        public ImageView model3Iv2;
        public ImageView model3Iv1;
        public ImageView model21Iv1;
        public TextView model21Tv2;
        public TextView model21Tv1;
        public LinearLayout home_skill_more_ll;
        public HorizontalListView skill_horizontal_hlv;
        public ScrollGridView gridview;
        public LinearLayout dotLl;
        public ViewPager viewPager;
        public HorizontalListView ocoffee_home_hlv;
        public LinearLayout hScrollView;

        public TextView getTimedown_second() {
            return timedown_second;
        }

        public void setTimedown_second(TextView timedown_second) {
            this.timedown_second = timedown_second;
        }

        public TextView getTimedown_min() {
            return timedown_min;
        }

        public void setTimedown_min(TextView timedown_min) {
            this.timedown_min = timedown_min;
        }

        public TextView getTimedown_hour() {
            return timedown_hour;
        }

        public void setTimedown_hour(TextView timedown_hour) {
            this.timedown_hour = timedown_hour;
        }

        public ViewPager getViewPager() {
            return viewPager;
        }

        public void setViewPager(ViewPager viewPager) {
            this.viewPager = viewPager;
        }
    }

    /**
     * 点赞监听
     *
     * @author Administrator
     */
    class MyWebLoadListener implements OnWebLoadListener<ZanBean> {
        View v;

        public MyWebLoadListener(View v) {
            this.v = v;
        }

        @Override
        public void OnStart() {
            // ((Activity)context).showDialog();
        }

        @Override
        public void OnError(String error) {
            // fragment.dismissDialog();
        }

        @Override
        public void onSuccess(ZanBean t) {
            try {
                // fragment.dismissDialog();
                if (t != null && t.getCode().equals("000000")) {
                    if (t.getResult().getLike().equals("1")) {
                        ArrayList<HomeItemContentBean> productList_list = MyApplication
                                .getInstance().getProductList();
                        for (int i = 0; null != productList_list
                                && i < productList_list.size(); i++) {
                            if (i == position_index) {
                                MyApplication.getInstance().getProductList()
                                        .get(i).setLike("1");
                            }
                        }
                    } else {
                        ArrayList<HomeItemContentBean> productList_list = MyApplication
                                .getInstance().getProductList();
                        for (int i = 0; null != productList_list
                                && i < productList_list.size(); i++) {
                            if (i == position_index) {
                                MyApplication.getInstance().getProductList()
                                        .get(i).setLike("0");
                            }
                        }
                    }
                    notifyDataSetChanged();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 主界面点击监听
     *
     * @author Administrator
     */
    class HomeClickListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            if (!MyApplication.isNetworkAvailable(context)) {
                return;
            }
            switch (v.getId()) {
                case R.id.homemodel_cb:
                    cbOnClick(v);
                    break;
                case R.id.homemodel_ll:
                    llOnClick(v);
                    break;
                case R.id.homemodel3_iv1:
                    onClickBanner(0,
                            Integer.parseInt(v.getTag(v.getId()).toString()));
                    break;
                case R.id.homemodel3_iv2:
                    onClickBanner(1,
                            Integer.parseInt(v.getTag(v.getId()).toString()));
                    break;
                case R.id.homemodel3_iv3:
                    onClickBanner(2,
                            Integer.parseInt(v.getTag(v.getId()).toString()));
                    break;
            }
        }
    }
}
